class Solution(object):
    def smallestRepunitDivByK(self, k):
        if k == 1:
            return 1
        num = 1
        d_set = {1}
        index = 1
        while num:
            index += 1
            num = (10 * num + 1) % k
            if num in d_set:
                return -1
            d_set.add(num)
        return index


